package com.zb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjProductIntroduce;
import com.zb.mapper.ZjProductIntroduceMapper;
import com.zb.service.ZjProductIntroduceService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 产品简介表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-08-17
 */
@Service
public class ZjProductIntroduceServiceImpl extends ServiceImpl<ZjProductIntroduceMapper, ZjProductIntroduce> implements ZjProductIntroduceService {

    // 新增或修改产品内额简介
    @Override
    public void save(Long custAccId, Long id, String content) {
        ZjProductIntroduce introduce = new ZjProductIntroduce();
        introduce.setId(id);
        introduce.setContent(content);

        QueryWrapper<ZjProductIntroduce> wrapper = new QueryWrapper<>();
        wrapper.select("id");
        wrapper.eq("id", id);
        if (null != this.getOne(wrapper)) {
            this.updateById(introduce);
            return;
        }
        introduce.setCustAccId(custAccId);
        this.save(introduce);
    }

    // 根据产品ID获取产品简介
    @Override
    public String getByProductId(Long id) {
        ZjProductIntroduce introduce = this.getById(id);
        return null == introduce? "" : introduce.getContent();
    }
}
